/*!
 * Ext JS Library 3.3.0
 * Copyright(c) 2006-2010 Ext JS, Inc.
 * licensing@extjs.com
 * http://www.extjs.com/license
 */

// Sample desktop configuration
var lockButton = new Ext.slider.SingleSlider({
	id:'lock-button',
	width:345,
	value:50,
	height:82,
	clickToChange:false,
	listeners:{
		'changecomplete':function(s,nv,t) {
							if (nv < 85) {
								s.setValue(50);
							} else {
								loginWindow.close();
							}
						}
	}
});

var loginWindow = new Ext.Window({
	id:'login-win',
	modal:true,
	width:480,
	height:440,
	resizable:false,
	bodyBorder:false,
	border:false,
	closable:false,
	draggable:false,
	layout:'form',
	padding:60,
	items:[
		{
			xtype:'textfield',
			emptyText:'Pass-code ...',
			hideLabel:true,
			style:{
				width:'100%',
				fontSize:'18px',
				height:'35px'
			}
		},
		lockButton,
		{
			xtype:'label',
			text:'Slide to unlock ...',
			style: {
				paddingTop:'90px',
				color:'#FFFFFF',
				fontSize:'16px'
			}
		}
	]
});

Ext.onReady(
	function() {
		loginWindow.show();
	}
);

MyDesktop = new Ext.app.App({
	init :function(){
		Ext.QuickTips.init();
	},

	getModules : function(){
		return [
			new MyDesktop.GridWindow(),
            new MyDesktop.TabWindow(),
            new MyDesktop.AccordionWindow(),
            new MyDesktop.BogusMenuModule(),
            new MyDesktop.BogusModule(),
			new MyDesktop.CallHistory(),
			new MyDesktop.Camera(),
			new MyDesktop.FileManager(),
			new MyDesktop.RegistryEditor(),
			new MyDesktop.Outlook()
		];
	},

    // config for the start menu
    getStartConfig : function(){
        return {
            title: 'Jack Slocum',
            iconCls: 'user',
            toolItems: [{
                text:'Settings',
                iconCls:'settings',
                scope:this
            },'-',{
                text:'Logout',
                iconCls:'logout',
                scope:this
            }]
        };
    }
});



/*
 * Example windows
 */
MyDesktop.GridWindow = Ext.extend(Ext.app.Module, {
    id:'grid-win',
    init : function(){
        this.launcher = {
            text: 'Grid Window',
            iconCls:'icon-grid',
            handler : this.createWindow,
            scope: this
        }
    },

    createWindow : function(){
        var desktop = this.app.getDesktop();
        var win = desktop.getWindow('grid-win');
        if(!win){
            win = desktop.createWindow({
                id: 'grid-win',
                title:'Grid Window',
                width:740,
                height:480,
                iconCls: 'icon-grid',
                shim:false,
                animCollapse:false,
                constrainHeader:true,

                layout: 'fit',
                items:
                    new Ext.grid.GridPanel({
                        border:false,
                        ds: new Ext.data.Store({
                            reader: new Ext.data.ArrayReader({}, [
                               {name: 'company'},
                               {name: 'price', type: 'float'},
                               {name: 'change', type: 'float'},
                               {name: 'pctChange', type: 'float'}
                            ]),
                            data: Ext.grid.dummyData
                        }),
                        cm: new Ext.grid.ColumnModel([
                            new Ext.grid.RowNumberer(),
                            {header: "Company", width: 120, sortable: true, dataIndex: 'company'},
                            {header: "Price", width: 70, sortable: true, renderer: Ext.util.Format.usMoney, dataIndex: 'price'},
                            {header: "Change", width: 70, sortable: true, dataIndex: 'change'},
                            {header: "% Change", width: 70, sortable: true, dataIndex: 'pctChange'}
                        ]),

                        viewConfig: {
                            forceFit:true
                        },
                        //autoExpandColumn:'company',

                        tbar:[{
                            text:'Add Something',
                            tooltip:'Add a new row',
                            iconCls:'add'
                        }, '-', {
                            text:'Options',
                            tooltip:'Blah blah blah blaht',
                            iconCls:'option'
                        },'-',{
                            text:'Remove Something',
                            tooltip:'Remove the selected item',
                            iconCls:'remove'
                        }]
                    })
            });
        }
        win.show();
    }
});

MyDesktop.TabWindow = Ext.extend(Ext.app.Module, {
    id:'tab-win',
    init : function(){
        this.launcher = {
            text: 'Tab Window',
            iconCls:'tabs',
            handler : this.createWindow,
            scope: this
        }
    },

    createWindow : function(){
        var desktop = this.app.getDesktop();
        var win = desktop.getWindow('tab-win');
        if(!win){
            win = desktop.createWindow({
                id: 'tab-win',
                title:'Tab Window',
                width:740,
                height:480,
                iconCls: 'tabs',
                shim:false,
                animCollapse:false,
                border:false,
                constrainHeader:true,

                layout: 'fit',
                items:
                    new Ext.TabPanel({
                        activeTab:0,

                        items: [{
                            title: 'Tab Text 1',
                            header:false,
                            html : '<p>Something useful would be in here.</p>',
                            border:false
                        },{
                            title: 'Tab Text 2',
                            header:false,
                            html : '<p>Something useful would be in here.</p>',
                            border:false
                        },{
                            title: 'Tab Text 3',
                            header:false,
                            html : '<p>Something useful would be in here.</p>',
                            border:false
                        },{
                            title: 'Tab Text 4',
                            header:false,
                            html : '<p>Something useful would be in here.</p>',
                            border:false
                        }]
                    })
            });
        }
        win.show();
    }
});

MyDesktop.AccordionWindow = Ext.extend(Ext.app.Module, {
    id:'acc-win',
    init : function(){
        this.launcher = {
            text: 'Accordion Window',
            iconCls:'accordion',
            handler : this.createWindow,
            scope: this
        }
    },

    createWindow : function(){
        var desktop = this.app.getDesktop();
        var win = desktop.getWindow('acc-win');
        if(!win){
            win = desktop.createWindow({
                id: 'acc-win',
                title: 'Accordion Window',
                width:250,
                height:400,
                iconCls: 'accordion',
                shim:false,
                animCollapse:false,
                constrainHeader:true,

                tbar:[{
                    tooltip:{title:'Rich Tooltips', text:'Let your users know what they can do!'},
                    iconCls:'connect'
                },'-',{
                    tooltip:'Add a new user',
                    iconCls:'user-add'
                },' ',{
                    tooltip:'Remove the selected user',
                    iconCls:'user-delete'
                }],

                layout:'accordion',
                border:false,
                layoutConfig: {
                    animate:false
                },

                items: [
                    new Ext.tree.TreePanel({
                        id:'im-tree',
                        title: 'Online Users',
                        loader: new Ext.tree.TreeLoader(),
                        rootVisible:false,
                        lines:false,
                        autoScroll:true,
                        tools:[{
                            id:'refresh',
                            on:{
                                click: function(){
                                    var tree = Ext.getCmp('im-tree');
                                    tree.body.mask('Loading', 'x-mask-loading');
                                    tree.root.reload();
                                    tree.root.collapse(true, false);
                                    setTimeout(function(){ // mimic a server call
                                        tree.body.unmask();
                                        tree.root.expand(true, true);
                                    }, 1000);
                                }
                            }
                        }],
                        root: new Ext.tree.AsyncTreeNode({
                            text:'Online',
                            children:[{
                                text:'Friends',
                                expanded:true,
                                children:[{
                                    text:'Jack',
                                    iconCls:'user',
                                    leaf:true
                                },{
                                    text:'Brian',
                                    iconCls:'user',
                                    leaf:true
                                },{
                                    text:'Jon',
                                    iconCls:'user',
                                    leaf:true
                                },{
                                    text:'Tim',
                                    iconCls:'user',
                                    leaf:true
                                },{
                                    text:'Nige',
                                    iconCls:'user',
                                    leaf:true
                                },{
                                    text:'Fred',
                                    iconCls:'user',
                                    leaf:true
                                },{
                                    text:'Bob',
                                    iconCls:'user',
                                    leaf:true
                                }]
                            },{
                                text:'Family',
                                expanded:true,
                                children:[{
                                    text:'Kelly',
                                    iconCls:'user-girl',
                                    leaf:true
                                },{
                                    text:'Sara',
                                    iconCls:'user-girl',
                                    leaf:true
                                },{
                                    text:'Zack',
                                    iconCls:'user-kid',
                                    leaf:true
                                },{
                                    text:'John',
                                    iconCls:'user-kid',
                                    leaf:true
                                }]
                            }]
                        })
                    }), {
                        title: 'Settings',
                        html:'<p>Something useful would be in here.</p>',
                        autoScroll:true
                    },{
                        title: 'Even More Stuff',
                        html : '<p>Something useful would be in here.</p>'
                    },{
                        title: 'My Stuff',
                        html : '<p>Something useful would be in here.</p>'
                    }
                ]
            });
        }
        win.show();
    }
});

// for example purposes
var windowIndex = 0;

MyDesktop.BogusModule = Ext.extend(Ext.app.Module, {
    init : function(){
        this.launcher = {
            text: 'Window '+(++windowIndex),
            iconCls:'bogus',
            handler : this.createWindow,
            scope: this,
            windowId:windowIndex
        }
    },

    createWindow : function(src){
        var desktop = this.app.getDesktop();
        var win = desktop.getWindow('bogus'+src.windowId);
        if(!win){
            win = desktop.createWindow({
                id: 'bogus'+src.windowId,
                title:src.text,
                width:640,
                height:480,
                html : '<p>Something useful would be in here.</p>',
                iconCls: 'bogus',
                shim:false,
                animCollapse:false,
                constrainHeader:true
            });
        }
        win.show();
    }
});

MyDesktop.BogusMenuModule = Ext.extend(MyDesktop.BogusModule, {
    init : function(){
        this.launcher = {
            text: 'Bogus Submenu',
            iconCls: 'bogus',
            handler: function() {
				return false;
			},
            menu: {
                items:[{
                    text: 'Bogus Window '+(++windowIndex),
                    iconCls:'bogus',
                    handler : this.createWindow,
                    scope: this,
                    windowId: windowIndex
                    },{
                    text: 'Bogus Window '+(++windowIndex),
                    iconCls:'bogus',
                    handler : this.createWindow,
                    scope: this,
                    windowId: windowIndex
                    },{
                    text: 'Bogus Window '+(++windowIndex),
                    iconCls:'bogus',
                    handler : this.createWindow,
                    scope: this,
                    windowId: windowIndex
                    },{
                    text: 'Bogus Window '+(++windowIndex),
                    iconCls:'bogus',
                    handler : this.createWindow,
                    scope: this,
                    windowId: windowIndex
                    },{
                    text: 'Bogus Window '+(++windowIndex),
                    iconCls:'bogus',
                    handler : this.createWindow,
                    scope: this,
                    windowId: windowIndex
                }]
            }
        }
    }
});

MyDesktop.CallHistory = Ext.extend(Ext.app.Module, {
	id:'callhistory-win',
    init : function(){
        this.launcher = {
            text: 'Call History',
            iconCls:'bogus',
            handler : this.createWindow,
            scope: this
        }
    },

    createWindow : function(){
        var desktop = this.app.getDesktop();
        var win = desktop.getWindow('callhistory-win');
        if(!win){
            win = desktop.createWindow({
                id: 'callhistory-win',
                title:'Call History',
                width:380,
                height:580,
                iconCls: 'bogus',
                shim:false,
                animCollapse:false,
                constrainHeader: true,
                layout: 'fit',
                items:
                    new Ext.TabPanel({
                        activeTab: 0,
                        items: [{ //Tabs
                            title: 'All Calls',
                            layout: 'fit',
							items: new Ext.grid.GridPanel({
								hideHeaders:true,
								loadMask:true,
                                border: false,
                                ds: dsCallHistory,
								bbar: {xtype: 'paging', pageSize:50, store: dsCallHistory},
                                cm: new Ext.grid.ColumnModel([
									{xtype:'templatecolumn', header: 'Calls', sortable: true,tpl: '<div><div style="float:left;"><img src="images/CallHistory/{CallType}.png" height="32px" style="float:left;margin-right:3px;">{Name}<br /><b>{Number}</b></div><div style="float:right;">{StartTime}<br /><b><i>Duration: {Duration}</i></b></div>  </div>'}
								]),
                                viewConfig: {
                                    forceFit: true
                                },
								listeners: {'viewready': function() { if (dsCallHistory.data.length==0) { dsCallHistory.load({'start':0,'limit':50}); } } }
                                }) //End of grid
                        } //End Of Tab Call History
						, {
                            title: 'Missed Calls',
                            layout: 'fit',
                            items: new Ext.grid.GridPanel({
								hideHeaders:true,
								loadMask:true,
                                border: false,
                                ds: dsMissedCalls,
								bbar: {xtype: 'paging', pageSize:50, store: dsMissedCalls},
                                cm: new Ext.grid.ColumnModel([
									{xtype:'templatecolumn', header: 'Calls', sortable: true,tpl: '<div><div style="float:left;"><img src="images/CallHistory/missed.png" height="32px" style="float:left;margin-right:3px;">{Name}<br /><b>{Number}</b></div><div style="float:right;">{StartTime}<br /></div>  </div>'}
								]),
                                viewConfig: {
                                    forceFit: true
                                },
								listeners: {'viewready': function() { if (dsMissedCalls.data.length==0) { dsMissedCalls.load({'start':0,'limit':50}); } } }
                                })
                        }, //End of missed calls tab
						{
                            title: 'Incoming Calls',
                            layout: 'fit',
                            items: new Ext.grid.GridPanel({
								hideHeaders:true,
								loadMask:true,
                                border: false,
                                ds: dsIncomingCalls,
								bbar: {xtype: 'paging', pageSize:50, store: dsIncomingCalls},
                                cm: new Ext.grid.ColumnModel([
									{xtype:'templatecolumn', header: 'Calls', sortable: true,tpl: '<div><div style="float:left;"><img src="images/CallHistory/incoming.png" height="32px" style="float:left;margin-right:3px;">{Name}<br /><b>{Number}</b></div><div style="float:right;">{StartTime}<br /><b><i>Duration: {Duration}</i></b></div>  </div>'}
								]),
                                viewConfig: {
                                    forceFit: true
                                },
								listeners: {'viewready': function() { if (dsIncomingCalls.data.length==0) { dsIncomingCalls.load({'start':0,'limit':50}); } } }
                                })
                        }, //End of incoming calls tab
						{
                            title: 'Tab Text 4',
                            header: false,
                            html: '<p>Something useful would be in here.</p>',
                            border: false
                            }]
                        }) //End of tabs
            });
        }
        win.show();
    }
});

MyDesktop.Camera = Ext.extend(Ext.app.Module, {
	id:'camera-win',
    init : function(){
        this.launcher = {
            text: 'Camera',
            iconCls:'bogus',
            handler : this.createWindow,
            scope: this
        }
    },

    createWindow : function(){
        var desktop = this.app.getDesktop();
        var win = desktop.getWindow('camera-win');
        if(!win){
            win = desktop.createWindow({
                id: 'camera-win',
                title:'Camera',
                width:650,
                height:500,
                iconCls: 'bogus',
                shim:false,
                animCollapse:false,
                constrainHeader: true,
				maskDisabled:false,
				html:'<b>Loading ...</b>',
				transactionId:0,
				taskMgr: {run: function() {
												win.setTitle('Camera - Loading ...');
												win.transactionId = Ext.Ajax.request({
													url: 'MOBIMIN-AJAX/CAMERA',
													success: function(response, opts) {
														var img = Ext.decode(response.responseText);
														win.setWidth(img.width+14);
														win.setHeight(img.height+32);
														win.body.update(img.src);
														win.setTitle('Camera');
													},
													failure: function(response, opts) {
														alert(response.status);
													}
												}); //End of ajax
											},
						interval: 10000, scope:this},
				listeners: {'show': function() { Ext.TaskMgr.start(this.taskMgr); }, 'close': function() { Ext.Ajax.abort(win.transactionId); Ext.TaskMgr.stop(this.taskMgr); }, 'minimize': function() { Ext.TaskMgr.stop(this.taskMgr); } },
                layout: 'fit' //,
                //items: {}
            });
        }
        win.show();
    }
}); // End of Camera window

MyDesktop.FileManager = Ext.extend(Ext.app.Module, {
	id:'filemanager-win',
    init : function(){
        this.launcher = {
            text: 'My Mobile',
            iconCls:'bogus',
            handler : this.createWindow,
            scope: this
        }
    },

    createWindow : function(){
        var desktop = this.app.getDesktop();
        var win = desktop.getWindow('filemanager-win');
        if(!win){
            win = desktop.createWindow({
                id: 'filemanager-win',
                title:'My Mobile',
                width:650,
                height:380,
                iconCls: 'bogus',
                shim:false,
                animCollapse:false,
                constrainHeader: true,
				maskDisabled:false,
				layout:'border',
				listeners: {'show': function() { dsFiles.load({params:{root:"My Mobile", start:0, limit:50}}); } },
                items:[
						{
							xtype:'treepanel',
							id:'tree-folders',
							width:150,
							title:'Folders',
							autoScroll:true,
							region:'west',
							split:true,
							useArrows: true,
							dataUrl:'MOBIMIN-AJAX/FOLDERS',
							requestMethod:'GET',
							listeners: {'click': function(node,event) { dsFiles.load({params:{root:node.id,start:0, limit:50}}) } },
							root: {
								nodeType: 'async',
								text: 'My Mobile',
								id: 'My Mobile'
							}
						},
						{
							xtype:'panel',
							layout:'fit',
							title:'My Mobile',
							region:'center',
							items: [{
								xtype:'grid',
								id:'grid-files',
								tbar:{
									xtype:'toolbar',
									items:[
										{xtype:'button',id:'b-newfolder',text:'New',icon:'resources/images/access/tree/folder.gif', handler:newFolder},
										{xtype:'button',id:'b-properties',disabled:true,text:'Properties',icon:'resources/images/access/tree/leaf.gif',handler:propertyFF},
										{xtype:'button',id:'b-delete',disabled:true,text:'Delete',icon:'resources/images/access/tree/drop-no.gif', handler:deleteFF},
										{xtype:'button',id:'b-rename',disabled:true,text:'Rename',icon:'resources/images/access/tree/drop-no.gif', handler:renameFF},
										'-',
										{xtype:'button',id:'b-download',disabled:true,text:'Download',icon:'resources/images/access/tree/drop-yes.gif', handler:downloadFile},
										{xtype:'button',id:'b-upload',text:'Upload',icon:'resources/images/access/tree/drop-yes.gif', handler:uploadFile}
									]
								},
								region:'center',
								loadMask:true,
								border:false,
								autoExpandColumn:true,
								columns: [
									{xtype:'templatecolumn',fixed:true,menuDisabled:true, sortable:false, dataIndex:'icon',width:28,tpl:'<img src="images/{icon}" width="16px" />'},
									{xtype:'gridcolumn', header:'Files', sortable:true, dataIndex:'fileName'},
									{xtype:'gridcolumn', header:'Type',sortable:true,dataIndex:'type'},
									{xtype:'gridcolumn', header:'Creation Time', sortable: true, dataIndex:'creationTime',width:140},
									{xtype:'templatecolumn', header:'Size', sortable:true,align:'right', dataIndex:'size', tpl:'{[fm.fileSize(values.size)]}'}
								],
								ds:dsFiles,
								bbar: {
										xtype:'paging',
										pageSize:50,
										store: dsFiles,
										displayInfo:true,
										listeners:{'beforechange': function(p, options) { 
																	//options.params.root=store.lastOptions.root;
																	options.root=p.store.lastOptions.params.root;
																	return true;
																}
													}
										}, //End of bbar
								listeners: {
											'viewready': function(grid) {
												grid.getSelectionModel().on('rowselect', function(sm, rowIndex, r) {
													if (r.data.type=="Folder") {
															grid.toolbars[0].items.items[1].setDisabled(false);
															grid.toolbars[0].items.items[2].setDisabled(false);
															grid.toolbars[0].items.items[3].setDisabled(false);
															grid.toolbars[0].items.items[5].setDisabled(true);
															//grid.toolbars[0].items.items[6].setDisabled(true);
														} else {
															grid.toolbars[0].items.items[1].setDisabled(false);
															grid.toolbars[0].items.items[2].setDisabled(false);
															grid.toolbars[0].items.items[3].setDisabled(false);
															grid.toolbars[0].items.items[5].setDisabled(false);
															//grid.toolbars[0].items.items[6].setDisabled(false);
														}
												  });
											}, //End of view ready
											'rowdblclick': function(grid,rowIndex,e) {
														if (this.store.data.items[rowIndex].data.type=="Folder") {
															var parentFolder = this.store.lastOptions.params.root;
															var oTree = desktop.getWindow('filemanager-win').items.items[0];
															oTree.getNodeById(parentFolder).expand(false,true, function(node) {
																node.ensureVisible();
																var folder= this.store.lastOptions.params.root + "/" + this.store.data.items[rowIndex].data.fileName;
																node.ownerTree.getNodeById(node.id + "/" + this.store.data.items[rowIndex].data.fileName).select();
																this.store.load({params:{root:folder,start:0, limit:50}});
																},
																this); //End of getNodeById
														} else {
															//TODO: Open file property window
														} //End if
											} //end of rowdblclick
										} //End of grid listeners
							}]
						}
						] //End of FileManager Items
            });
        }
        win.show();
    }
}); // End of File Manager window

MyDesktop.RegistryEditor = Ext.extend(Ext.app.Module, {
	id:'registryeditor-win',
    init : function(){
        this.launcher = {
            text: 'Registry Editor',
            iconCls:'bogus',
            handler : this.createWindow,
            scope: this
        }
    },

    createWindow : function(){
        var desktop = this.app.getDesktop();
        var win = desktop.getWindow('registryeditor-win');
        if(!win){
            win = desktop.createWindow({
                id: 'registryeditor-win',
                title:'Registry Editor',
                width:650,
                height:380,
                iconCls: 'bogus',
                shim:false,
                animCollapse:false,
                constrainHeader: true,
				maskDisabled:false,
				layout:'border',
				listeners: {'show': function() { dsRegistry.load({params:{root:"Registry", start:0, limit:50}});} },
                items:[
						{
							xtype:'treepanel',
							id:'tree-registry',
							width:200,
							title:'Registry',
							autoScroll:true,
							region:'west',
							split:true,
							useArrows: true,
							dataUrl:'MOBIMIN-AJAX/REGISTRY',
							requestMethod:'GET',
							listeners: {'click': function(node,event) { dsRegistry.load({params:{root:node.id,start:0, limit:50}}) } },
							root: {
								nodeType: 'async',
								text: 'Registry',
								id:'Registry'
							}
						},
						{
							xtype:'panel',
							layout:'fit',
							title:'Registry',
							region:'center',
							items: [{
								xtype:'grid',
								id:'grid-registry',
								tbar:{
									xtype:'toolbar',
									items:[
										{xtype:'button',
										id:'b-newregistry',
										text:'New',
										icon:'resources/images/access/tree/folder.gif',
										menu: new Ext.menu.Menu({
										items: [
											{text:'Key',icon:'images/reg_Key.png',handler:NewRegistryKey},
											{text:'String Value',icon:'images/reg_String.png',handler:NewRegistryString},
											{text:'DWORD Value',icon:'images/reg_DWORD.png'},
											{text:'Binary Value',icon:'images/reg_Binary.png'},
											{text:'Multi-String Value',icon:'images/reg_MultiString.png'},
											{text:'Expandable String Value',icon:'images/reg_ExpandString.png'}
											]
										}) //End of Split (new) Menu
										},
										{xtype:'button',id:'b-properties',disabled:true,text:'Properties',icon:'resources/images/access/tree/leaf.gif'},
										{xtype:'button',id:'b-delete',disabled:true,text:'Delete',icon:'resources/images/access/tree/drop-no.gif', handler:deleteFF},
										{xtype:'button',id:'b-rename',disabled:true,text:'Rename',icon:'resources/images/access/tree/drop-no.gif', handler:renameFF},
										'-',
										{xtype:'button',id:'b-download',disabled:true,text:'Download',icon:'resources/images/access/tree/drop-yes.gif', handler:downloadFile},
										{xtype:'button',id:'b-upload',disabled:true,text:'Upload',icon:'resources/images/access/tree/drop-yes.gif', handler:uploadFile}
									]
								},
								region:'center',
								loadMask:true,
								border:false,
								autoExpandColumn:true,
								columns: [
									{xtype:'templatecolumn',fixed:true,menuDisabled:true, sortable:false, dataIndex:'icon',width:28,tpl:'<img width="16px" src="images/reg_{type}.png" />'},
									{xtype:'gridcolumn', header:'Name', sortable:true, dataIndex:'name'},
									{xtype:'gridcolumn', header:'Type',sortable:true,dataIndex:'type'},
									{xtype:'gridcolumn', header:'Data', sortable: true, dataIndex:'data'}
								],
								ds:dsRegistry,
								bbar: {
										xtype:'paging',
										pageSize:50,
										store: dsRegistry,
										listeners:{'beforechange': function(p, options) { 
																	//options.params.root=store.lastOptions.root;
																	options.root=p.store.lastOptions.params.root;
																	return true;
																}
													}
										}, //End of bbar
								listeners: {
											'viewready': function(grid) {
												grid.getSelectionModel().on('rowselect', function(sm, rowIndex, r) {
													if (r.data.type=="Key") {
															grid.toolbars[0].items.items[1].setDisabled(false);
															grid.toolbars[0].items.items[2].setDisabled(false);
															grid.toolbars[0].items.items[3].setDisabled(false);
															grid.toolbars[0].items.items[5].setDisabled(true);
															grid.toolbars[0].items.items[6].setDisabled(true);
														} else {
															grid.toolbars[0].items.items[1].setDisabled(false);
															grid.toolbars[0].items.items[2].setDisabled(false);
															grid.toolbars[0].items.items[3].setDisabled(false);
															grid.toolbars[0].items.items[5].setDisabled(false);
															grid.toolbars[0].items.items[6].setDisabled(false);
														}
												  });
											}, //End of view ready
											'rowdblclick': function(grid,rowIndex,e) {
														if (this.store.data.items[rowIndex].data.type=="Key") {
															var parentFolder = this.store.lastOptions.params.root;
															var oTree = desktop.getWindow('registryeditor-win').items.items[0];
															oTree.getNodeById(parentFolder).expand(false,true, function(node) {
																node.ensureVisible();
																var folder= this.store.lastOptions.params.root + "/" + this.store.data.items[rowIndex].data.name;
																node.ownerTree.getNodeById(node.id + "/" + this.store.data.items[rowIndex].data.name).select();
																this.store.load({params:{root:folder,start:0, limit:50}});
																},
																this); //End of getNodeById
														} else {
															//TODO: Open file property window
														} //End if
											} //end of rowdblclick
										} //End of grid listeners
							}]
						}
						] //End of FileManager Items
            });
        }
        win.show();
    }
}); // End of Registry Manager window



MyDesktop.Outlook = Ext.extend(Ext.app.Module, {
    id:'outlook-win',
    init : function(){
        this.launcher = {
            text: 'Pocket Outlook',
            iconCls:'icon-grid',
            handler : this.createWindow,
            scope: this
        }
    },

    createWindow : function(){
        var desktop = this.app.getDesktop();
        var win = desktop.getWindow('outlook-win');
        if(!win){
            win = desktop.createWindow({
                id: 'outlook-win',
                title:'Pocket Outlook',
                width:740,
                height:400,
                iconCls: 'icon-grid',
                shim:false,
                animCollapse:false,
                constrainHeader:true,
                layout: 'border',
                items:[
						{
							xtype:'panel',
							region:'west',
							split:true,
							width:200,
							border:false,
							layout:'accordion',
							layoutConfig: {
								animate: true,
								activeOnTop: true
							},
							items:[
									{
										title: 'Contacts',
										padding:4,
										items:[
											{
												xtype:'panel',
												frame:true,
												title: 'Contact Actions',
												collapsible:true,
												titleCollapse: true,
												html:'<a href=#>Add new contact</a>',
												bodyCfg: {
															handler: function() {alert(1);}
												}
											}
										],
										autoScroll:true,
										listeners: {
														'activate':function() {
																	var grids = MyDesktop.desktop.getWindow('outlook-win'); //.items.items[1].items;
																	if (grids) {
																		ShowOutlookGrid(0);
																	}
																}
										}
									},
									{
										title: 'SMS',
										html:'<p>Something useful would be in here.</p>',
										autoScroll:true,
										listeners: {'activate':function() {
																ShowOutlookGrid(1);
																}
													
													}
									},
									{
										title: 'Tasks',
										html:'<p>Something useful would be in here.</p>',
										autoScroll:true,
										listeners: {'activate':function() {
																ShowOutlookGrid(2);
																}
													
													}
									},
									{
										title: 'Appointments',
										html:'<p>Something useful would be in here.</p>',
										autoScroll:true,
										listeners: {'activate':function() {
																ShowOutlookGrid(3);
																}
													
													}
									}
									]
						},
						{
							xtype:'panel',
							region:'center',
							layout:'vbox',
							layoutConfig: {
								align : 'stretch',
								pack  : 'start'
							},
							border:false,
							items:[
									{
										xtype:'grid',
										title:'Contacts',
										region:'center',
										store:dsGroupingContacts,
										view: new Ext.grid.GroupingView({
													forceFit:true,
													groupTextTpl: '{text} ({[values.rs.length]} {[values.rs.length > 1 ? "Contacts" : "Contact"]})'
												}),
										hidden:false,
										flex:1,
										viewConfig:{forceFit:true},
										autoHeight:false,
										cm: new Ext.grid.ColumnModel({
											columns: [ 
												{xtype:'gridcolumn',hidden:true,header:'itemId', dataIndex:'itemId'},
												{xtype:'templatecolumn', header:'Photo',width:55,fixed:true, resizable:false, tpl:'<img src="{contactPhoto}" width="45" />'},
												{xtype:'templatecolumn', header:'Full Name', tpl:'Name: <b>{fullName}</b><br /><i>{fileAs}</i>'},
												{xtype:'templatecolumn', header:'Phones',tpl:'<div><img src="images/email_go.png" /> {mobile}</div><div><img src="images/email_go.png" />{homePhone}</div>'},
												{xtype:'templatecolumn', header:'B. Phones', tpl:'<img src="images/email_go.png" />{businessPhone}<br /><img src="images/email_go.png" />{businessFax}'},
												{xtype:'templatecolumn', header:'URLs', tpl:'<img src="images/email_go.png" />{email}<br /><img src="images/email_go.png" />{webPage}'},
												{xtype:'gridcolumn',hidden:true,header:'Category', dataIndex:'category'}
											]
										})
									},
									{
										xtype:'grid',
										title:'SMS',
										region:'center',
										store:dsFiles,
										hidden:true,
										flex:2,
										viewConfig:{forceFit:true},
										autoHeight:false,
										columns:[ 
											{xtype:'templatecolumn',header:'All Days', tpl:'{allDaysEvent}'},
											{xtype:'templatecolumn',header:'Description', tpl:'{body}'},
											{xtype:'templatecolumn',header:'Busy Status', tpl:'{busyStatus}'},
											{xtype:'templatecolumn',header:'Categories', tpl:'{categories}'},
											{xtype:'templatecolumn',header:'Duration', tpl:'{duration}'},
											{xtype:'templatecolumn',header:'Start', tpl:'{start}'},
											{xtype:'templatecolumn',header:'End', tpl:'{end}'},
											{xtype:'templatecolumn',header:'Location', tpl:'{locations}'}
										]
									},
									{
										xtype:'grid',
										title:'Tasks',
										id:'tasks-grid',
										region:'center',
										store:dsTasks,
										hidden:true,
										flex:3,
										autoHeight:false,
										plugins: completeColumn,
										cm: new Ext.grid.ColumnModel({
											columns:[
												completeColumn,
												{xtype:'templatecolumn',header:'Subject', tpl:'{subject}'},
												{xtype:'templatecolumn',header:'Start Date', tpl:'{startDate}'},
												{xtype:'templatecolumn',header:'Due Date', tpl:'{dueDate}'},
												{xtype:'templatecolumn',header:'Priority', tpl:'{importance}',width:57,fixed:true},
												{xtype:'templatecolumn',header:'Sensitivity', tpl:'{sensitivity}',width:75},
												{xtype:'templatecolumn',header:'Categories', tpl:'{categories}',width:70,fixed:true},
												{xtype:'templatecolumn',header:'Description', tpl:'{body}'}
											]
										}),
										view: new Ext.grid.GridView({
											forceFit:true,
											ignoreAdd: true,
											markDirty:false,
											emptyText: 'No Tasks to display',
											getRowClass : function(r){
												var d = r.data;
												if(d.complete){
													return 'task-completed';
												}
												return '';
											}
										}), //End of view
										sm: new Ext.grid.RowSelectionModel({
											singleSelect:true
										})
									},
									{
										xtype:'grid',
										title:'Appointments',
										region:'center',
										store:dsAppointments,
										hidden:true,
										flex:4,
										viewConfig:{forceFit:true},
										autoHeight:false,
										columns:[
											{xtype:'templatecolumn',header:'AllDays', tpl:'{allDaysEvent}',width:55,fixed:true},
											{xtype:'templatecolumn',header:'Subject', tpl:'<{dueStyle}>{subject}</{dueStyle}>'},
											{xtype:'templatecolumn',header:'Start', tpl:'{start}'},
											{xtype:'templatecolumn',header:'End', tpl:'{end}'},
											{xtype:'templatecolumn',header:'Duration', tpl:'{duration}',width:65,fixed:true},
											{xtype:'templatecolumn',header:'Categories', tpl:'{categories}', width:60},
											{xtype:'templatecolumn',header:'Location', tpl:'{location}'}
										]
									}
							]
						}
				]
				});
		}
		win.show();
	} //End of create window
});
// Aray data for the grid





Ext.grid.dummyData = [
    
    ['Wal-Mart Stores, Inc.',45.45,0.73,1.63,'9/1 12:00am'],
    ['Walt Disney Company (The) (Holding Company)',29.89,0.24,0.81,'9/1 12:00am']
];

var dsCallHistory = new Ext.data.JsonStore({
    // store configs
    autoDestroy: false,
	root:'rows',
	totalProperty: 'results',
	baseParams:{start:0, limit:50},
    proxy : new Ext.data.HttpProxy({
		method: 'GET',
		url: 'MOBIMIN-AJAX/CALLHISTORY'
		}),
    storeId: 'dsCallHistory',
    listeners: {'beforeload': function() {} },
    fields: ['Name', 'Number', 'StartTime', 'EndTime', 'CallType', 'Duration']
});

var dsMissedCalls = new Ext.data.JsonStore({
    // store configs
    autoDestroy: false,
	root:'rows',
	totalProperty: 'results',
	baseParams:{start:0, limit:50},
    proxy : new Ext.data.HttpProxy({
		method: 'GET',
		url: 'MOBIMIN-AJAX/missedcalls'
		}),
    storeId: 'dsMissedCalss',
    fields: ['Name', 'Number', 'StartTime', 'EndTime']
});

var dsIncomingCalls = new Ext.data.JsonStore({
    // store configs
    autoDestroy: false,
	root:'rows',
	totalProperty: 'results',
	baseParams:{start:0, limit:50},
    proxy : new Ext.data.HttpProxy({
		method: 'GET',
		url: 'MOBIMIN-AJAX/incomingcalls'
		}),
    storeId: 'dsIncomingCalls',
    fields: ['Name', 'Number', 'StartTime', 'EndTime', 'CallType', 'Duration']
});

var trayTaskMgr = {
	run: function() {
		//MyDesktop.desktop.taskbar.trayPanel.items.items[0].update('<img src="images/signal/wifi-on.png" title="' + Math.random() +  '" />');
		//MyDesktop.desktop.taskbar.trayPanel.items.items[0].setVisible(false);
		Ext.Ajax.request({
			url: 'MOBIMIN-AJAX/STATUS',
			success: function(response, opts) {
				var phoneStatus = Ext.decode(response.responseText);
				MyDesktop.desktop.taskbar.trayPanel.items.items[0].update('<img src="images/signal/wifi-on.png" title="' + phoneStatus.signal +  '" />');
				MyDesktop.desktop.taskbar.trayPanel.items.items[1].update('<img src="images/signal/wifi-on.png" title="' + phoneStatus.operatorName +  '" />');
				MyDesktop.desktop.taskbar.trayPanel.items.items[2].update('<img src="images/signal/wifi-on.png" title="' + phoneStatus.soundLevel +  '" />');
			},
			failure: function(response, opts) {
				//alert(response.status);
			}
		}); //End of ajax
	},	
	interval:10000
}


Ext.onReady(
	function() {
		//Ext.TaskMgr.start(trayTaskMgr);
	}
);
//

var dsFiles = new Ext.data.JsonStore({
    // store configs
    autoDestroy:false,
	root:'rows',
	totalProperty: 'result',
	baseParams: {root:'\/',start:0, limit:50},
	autoLoad:false,
	remoteSort:true,
	paramNames: {
		sort:'sortField',
		dir:'direction'
	},
	sortInfo: {
		field:'fileName',
		direction:'ASC'
	},
    proxy : new Ext.data.HttpProxy({
		method: 'GET',
		url: 'MOBIMIN-AJAX/FILES'
		}),
    storeId: 'dsFiles',
    fields:['fileName','creationTime','size','type','icon'],
	listeners: {
		'load': function(store,record,options) {
					var filePanel=MyDesktop.desktop.getWindow('filemanager-win').items.items[1];
					filePanel.setTitle(options.params.root);
					var girdFiles = filePanel.items.items[0];
					girdFiles.toolbars[0].items.items[1].setDisabled(true);
					girdFiles.toolbars[0].items.items[2].setDisabled(true);
					girdFiles.toolbars[0].items.items[3].setDisabled(true);
					girdFiles.toolbars[0].items.items[5].setDisabled(true);
					//girdFiles.toolbars[0].items.items[6].setDisabled(true);
				}
	}
});

var dsRegistry = new Ext.data.JsonStore({
    // store configs
    autoDestroy:false,
	root:'rows',
	totalProperty:'results',
	baseParams: {root:'Registry',start:0, limit:50},
	autoLoad:false,
    proxy : new Ext.data.HttpProxy({
		method: 'GET',
		url: 'MOBIMIN-AJAX/REGISTRYKEYS'
		}),
    storeId:'dsRegistry',
    fields:['name','type','data'],
	listeners: {
		'load': function(store,record,options) {
					/*var filePanel=MyDesktop.desktop.getWindow('registrymanager-win').items.items[1];
					filePanel.setTitle(options.params.root);
					var girdFiles = filePanel.items.items[0];
					girdFiles.toolbars[0].items.items[1].setDisabled(true);
					girdFiles.toolbars[0].items.items[2].setDisabled(true);
					girdFiles.toolbars[0].items.items[3].setDisabled(true);
					girdFiles.toolbars[0].items.items[5].setDisabled(true);
					girdFiles.toolbars[0].items.items[6].setDisabled(true);*/
				}
	}
});

var dsContacts = new Ext.data.JsonReader({
    // store configs
    autoDestroy:false,
	idProperty: 'itemId',
	root:'rows',
	totalProperty:'results',
	autoLoad:true,
    storeId:'dsContacts',
    fields:['itemId','fullName','mobile', 'jobTitle', 'company', 'fileAs', 'country', 'department', 'businessPhone', 'businessFax', 'homePhone', 'email', 'category', 'contactPhoto', 'nikeName', 'webPage'],
	listeners: {
		'load': function(store,record,options) {
					
				}
	}
});

var dsGroupingContacts = new Ext.data.GroupingStore({
	reader: dsContacts,
	storeId:'dsGroupingContacts',
	storeInfo:{field:'category', direction:"ASC"},
	autoLoad:true,
	groupField:'category',
	baseParams: {action:'contacts'},
	proxy : new Ext.data.HttpProxy({
		method: 'GET',
		url: 'MOBIMIN-AJAX/OUTLOOK'
		})
});

var dsAppointments = new Ext.data.JsonStore({
    // store configs
    autoDestroy: false,
	autoLoad:true,
	root:'rows',
	totalProperty: 'results',
	baseParams:{action:'appointments'},
    proxy : new Ext.data.HttpProxy({
		method: 'GET',
		url: 'MOBIMIN-AJAX/OUTLOOK'
		}),
    storeId: 'dsAppointments',
    listeners: {'beforeload': function() {} },
	fields: ['allDaysEvent', 'body', 'busyStatus', 'categories', 'duration', 'end','itemId','location','start','dueStyle','subject']
});

var dsTasks = new Ext.data.JsonStore({
    // store configs
    autoDestroy: false,
	autoLoad:true,
	root:'rows',
	totalProperty: 'results',
	baseParams:{action:'tasks'},
    proxy : new Ext.data.HttpProxy({
		method: 'GET',
		url: 'MOBIMIN-AJAX/OUTLOOK'
		}),
    storeId: 'dsTasks',
    listeners: {'beforeload': function() {} },
	fields: ['body','categories', 'complete', 'dueDate','itemId','importance','sensitivity','startDate','subject']
});

//Functions

function propertyFF() {
	//MyDesktop.desktop.getWindow('filemanager-win').setDisabled(true);
	SAMEH=MyDesktop.desktop.getWindow('filemanager-win');
	var parentFolder = dsFiles.lastOptions.params.root;
	var filePanel=MyDesktop.desktop.getWindow('filemanager-win').items.items[1];
	var gridFiles = filePanel.items.items[0];
	var row = gridFiles.selModel.selections.items[0].data;
	var data=row.fileName;
	var type=row.type;
	Ext.Ajax.request({
	url: 'MOBIMIN-AJAX/FILEMANAGER',
	params: { action:'property',parentFolder:parentFolder,data:data,type:type },
	method:'GET',
	success: function(response, opts) {
			var res = Ext.decode(response.responseText);
			if (res.success) {
				//refresh
				var pwin = new Ext.Window({
					title:data + ' Properties',
					modal:true,
					width:320,
					height:360,
					layout:'form',
					resizable:false,
					padding:10,
					buttons:[
						{xtype:'button', text:'OK', scope:this, handler:function() {pwin.close(); }}
					],
					labelWidth:75,
					defaults:{
						
					},
					items:[
						{xtype:'textfield',grow:true,fieldLabel:'File Name',readOnly:true,value:data},
						{xtype:'label',html:'<hr />'},
						{xtype:'label',fieldLabel:'Type',text:type},
						{xtype:'label',fieldLabel:'Location',text:res.fullName},
						{xtype:'label',fieldLabel:'Contains',text:res.filesCount+' Files, ' + res.directoriesCount + ' Folders'},
						{xtype:'label',fieldLabel:'Size',text:Ext.util.Format.fileSize(res.length)},
						{xtype:'label',html:'<hr />'},
						{xtype:'label',fieldLabel:'Created',text:res.creationTime},
						{xtype:'label',fieldLabel:'Modified',text:res.lastWriteTime},
						{xtype:'label',fieldLabel:'Accessed',text:res.lastAccessTime},
						{xtype:'label',html:'<hr />'},
						{xtype:'label',fieldLabel:'Attributes',text:res.attributes}
					],
					listeners:{
						'hide': function() {
							//MyDesktop.desktop.getWindow('filemanager-win').setDisabled(false);
						}
					}
				});
				pwin.show();
			} else {
				//MyDesktop.desktop.getWindow('filemanager-win').setDisabled(false);
			}
	},
	failure: function(response, opts) {
	SAMEH=response;
		alert(response.status);
	}
}); //End of ajax
}

function newFolder() {
	Ext.Msg.prompt('New Folder', 'Folder Name:', function(btn, text){
		if (btn == 'ok'){
			var parentFolder = dsFiles.lastOptions.params.root;
			Ext.Ajax.request({
				url: 'MOBIMIN-AJAX/FILEMANAGER',
				params: { action:'newfolder',parentFolder:parentFolder,data:text },
				method:'GET',
				success: function(response, opts) {
						var res = Ext.decode(response.responseText);
						if (res.success) {
							//refresh
							reloadNode();
							dsFiles.reload();
						} else {
						
						}
				},
				failure: function(response, opts) {
					alert(response.status);
				}
			}); //End of ajax
		}
	});
}

function deleteFF() {
	Ext.Msg.confirm('Delete', 'Are you sure you want to delete this folder/file?', function(btn, text){
		if (btn == 'yes'){
			var parentFolder = dsFiles.lastOptions.params.root;
			var filePanel=MyDesktop.desktop.getWindow('filemanager-win').items.items[1];
			var gridFiles = filePanel.items.items[0];
			var row = gridFiles.selModel.selections.items[0].data;
			var action= (row.type=='Folder'?'deletefolder':'deletefile');
			var data=row.fileName;
			Ext.Ajax.request({
				url: 'MOBIMIN-AJAX/FILEMANAGER',
				params: { action:action,parentFolder:parentFolder,data:data },
				method:'GET',
				success: function(response, opts) {
						var res = Ext.decode(response.responseText);
						if (res.success) {
							//refresh
							reloadNode();
							dsFiles.reload();
						} else {
						
						}
				},
				failure: function(response, opts) {
					alert(response.status);
				}
			}); //End of ajax
		}
	});
}

function reloadNode() {
	var parentFolder = dsFiles.lastOptions.params.root;
	var currentNode=MyDesktop.desktop.getWindow('filemanager-win').items.items[0].getNodeById(parentFolder);
	if (currentNode.expanded) {
		currentNode.reload();
	}
}

function renameFF() {
Ext.Msg.prompt('Rename', 'New Name:', function(btn, text){
if (btn == 'ok'){
	var parentFolder = dsFiles.lastOptions.params.root;
	var filePanel=MyDesktop.desktop.getWindow('filemanager-win').items.items[1];
	var gridFiles = filePanel.items.items[0];
	var row = gridFiles.selModel.selections.items[0].data;
	var action= (row.type=='Folder'?'renamefolder':'renamefile');
	var data=row.fileName;
	Ext.Ajax.request({
		url: 'MOBIMIN-AJAX/FILEMANAGER',
		params: { action:action,parentFolder:parentFolder,data:data,newName:text },
		method:'GET',
		success: function(response, opts) {
				var res = Ext.decode(response.responseText);
				if (res.success) {
					//refresh
					reloadNode();
					dsFiles.reload();
				} else {
				
				}
		},
		failure: function(response, opts) {
			alert(response.status);
		}
	}); //End of ajax
} // End if
});
} //End Of Rename

function downloadFile() {
	var parentFolder = dsFiles.lastOptions.params.root;
	var filePanel=MyDesktop.desktop.getWindow('filemanager-win').items.items[1];
	var gridFiles = filePanel.items.items[0];
	var row = gridFiles.selModel.selections.items[0].data;
	var data=row.fileName;
	top.location.href='MOBIMIN-DOWNLOAD?_dc=8475638&parentFolder=' + parentFolder + "&fileName=" + data ;
} //end of function downloadFile

var wUpload;
function uploadFile() {
	wUpload= new Ext.Window({
		height: 112,
		width: 400,
		modal: true,
		layout:'fit',
		items:fileUploader,
		closeAction:'hide',
		resizable:false,
		title:'Uploadting to: ' + dsFiles.lastOptions.params.root
	});
	wUpload.show()
} //end of upload file

var fileUploader = new Ext.FormPanel({
        fileUpload:true,
        frame:true,
        autoHeight: true,
		border:true,
		bodyStyle: 'padding: 10px 10px 0 10px;',
        labelWidth: 35,
        defaults: {
			anchor:'95%',
            allowBlank: false,
            msgTarget: 'side'
        },
        items: [
			{
				xtype:'fileuploadfield',
				id:'form-file',
				emptyText:'Select a file',
				fieldLabel:'File',
				name:'file-path',
				buttonText:'...'
			}],
        buttons: [{
            text:'Save',
            handler: function(){
                if(fileUploader.getForm().isValid()){
	                fileUploader.getForm().submit({
	                    url:dsFiles.lastOptions.params.root,
	                    waitMsg: 'Uploading your file...',
	                    success: function(fp, o){
						    wUpload.hide();
							dsFiles.reload();
							Ext.Mobimin.msg('File Upload', 'File uploaded successfuly');
	                    }
	                });
                }
            }
        },{
            text: 'Reset',
            handler: function(){
                fileUploader.getForm().reset();
            }
        }]
    });

function NewRegistryKey() {
	Ext.Msg.prompt('New Key', 'Key Name:', function(btn, text){
		if (btn == 'ok'){
			var parentNode = dsRegistry.lastOptions.params.root;
			Ext.Ajax.request({
				url: 'MOBIMIN-AJAX/REGISTRYMANAGER',
				params: { action:'newkey',parentNode:parentNode,data:text },
				method:'GET',
				success: function(response, opts) {
						var res = Ext.decode(response.responseText);
						if (res.success) {
							//refresh
							dsRegistry.reload();
							Ext.Mobimin.msg('New Key', 'Key created successfuly');
						} else {
							//Ext.Mobimin.msg('Button Click', 'You clicked the {0} button', 1);
							alert(res.msg);
						}
				},
				failure: function(response, opts) {
					alert(response.status);
				}
			}); //End of ajax
		}
	}); 
} // End of function RegistryKey 



function NewRegistryValue(kind) {

var WinRegistry = new Ext.Window({
	width:300,
	height:220,
	modal:true,
	title:'New String Value',
	zindex:2000,
	bodyStyle: 'padding: 10px 10px 0 10px;',
	layout:'form',
	labelWidth: 42,
        defaults: {
			anchor:'95%',
            allowBlank: false,
            msgTarget: 'side'
        },
	 items: [{
            xtype: 'textfield',
            fieldLabel:'Name',
			emptyText:'New String Name ...'
        },{
            xtype:'textfield',
            fieldLabel:'Value',
			allowBlank:true
        }],
	buttons:[{
				text:'Save',
				scope:this,
				handler: function() {
							var parentNode = dsRegistry.lastOptions.params.root;
							var ValueName=WinRegistry.items.items[0].getValue();
							var ValueData=WinRegistry.items.items[1].getValue();
							Ext.Ajax.request({
							url: 'MOBIMIN-AJAX/REGISTRYMANAGER',
							params: { action:'new-string',parentNode:parentNode,valueName:ValueName,valueData:ValueData },
							method:'GET',
							success: function(response, opts) {
									var res = Ext.decode(response.responseText);
									if (res.success) {
										//refresh
										WinRegistry.hide();
										dsRegistry.reload();
										Ext.Mobimin.msg('New Value', 'String created successfuly');
									} else {
										//Ext.Mobimin.msg('Button Click', 'You clicked the {0} button', 1);
										alert(res.msg);
									}
							},
							failure: function(response, opts) {
								alert(response.status);
							}
						}); //End of ajax
				}
			},{
				text:'Cancel',
				handler:function(){ WinRegistry.hide(); }
			}]
}); //End of WinRegistry
WinRegistry.show();

return
	Ext.Msg.prompt('New Key', 'Key Name:', function(btn, text){
		if (btn == 'ok'){
			var parentNode = dsRegistry.lastOptions.params.root;
			Ext.Ajax.request({
				url: 'MOBIMIN-AJAX/REGISTRYMANAGER',
				params: { action:'newkey',parentNode:parentNode,data:text },
				method:'GET',
				success: function(response, opts) {
						var res = Ext.decode(response.responseText);
						if (res.success) {
							//refresh
							dsRegistry.reload();
							Ext.Mobimin.msg('New Key', 'Key created successfuly');
						} else {
							//Ext.Mobimin.msg('Button Click', 'You clicked the {0} button', 1);
							alert(res.msg);
						}
				},
				failure: function(response, opts) {
					alert(response.status);
				}
			}); //End of ajax
		} //End if
	}); 
} // End of function NewValue 

function NewRegistryString() {
	//NewRegistryValue('new-string');
	NewRegistryValue();
} //End of NewRegistryString

function ShowOutlookGrid(gridIndex) {
	var grids = MyDesktop.desktop.getWindow('outlook-win').items.items[1].items.items; 
	grids[0].setVisible(false);
	grids[1].setVisible(false);
	grids[2].setVisible(false);
	grids[3].setVisible(false);
	grids[gridIndex].setVisible(true);
	MyDesktop.desktop.getWindow('outlook-win').doLayout();
}


//Plugins

 var completeColumn = new CompleteColumn();
 
//dsCallHistory.load();

//new Ext.data.Store({
//    reader: new Ext.data.ArrayReader({}, [
//                               { name: 'company' },
//                               { name: 'price', type: 'float' },
//                               { name: 'change', type: 'float' },
//                               { name: 'pctChange', type: 'float' }
//                            ]),
//    data: Ext.grid.dummyData
//})